@handled
Feature: Reporting handled errors

  Scenario Outline: calling notify() with Error
    When I navigate to the test URL "/handled/<type>/notify_new_error.html"
    Then I wait to receive an error
    And the error is a valid browser payload for the error reporting API
    And the exception "errorClass" equals "Error"
    And the exception "message" equals "bad things"
    And the exception "type" equals "browserjs"
    And the error payload field "events.0.app.type" equals "browser"
    And event 0 is handled

    Examples:
      | type       |
      | script     |
      | webpack3   |
      | webpack4   |
      | browserify |
      | rollup     |
      | typescript |

  Scenario Outline: calling notify() with Error within try/catch
    When I navigate to the test URL "/handled/<type>/try_catch_notify.html"
    Then I wait to receive an error
    And the error is a valid browser payload for the error reporting API
    And the exception matches the "handled" values for the current browser
    And the exception "type" equals "browserjs"
    And event 0 is handled

    Examples:
      | type       |
      | script     |
      | webpack3   |
      | webpack4   |
      | browserify |
      | rollup     |
      | typescript |

  @requires_promise
  Scenario Outline: calling notify() with Error within Promise catch
    When I navigate to the test URL "/handled/<type>/promise_catch.html"
    Then I wait to receive an error
    And the error is a valid browser payload for the error reporting API
    And the exception "errorClass" equals "Error"
    And the exception "message" equals "bad things"
    And the exception "type" equals "browserjs"
    And event 0 is handled

    Examples:
      | type       |
      | script     |
      | webpack3   |
      | webpack4   |
      | browserify |
      | rollup     |
      | typescript |

  Scenario: calling notify() with an object, getting a generated a stacktrace
    When I navigate to the test URL "/handled/script/notify_object.html"
    Then I wait to receive an error
    And the error is a valid browser payload for the error reporting API
    And the exception "errorClass" equals "Errr"
    And the exception "message" equals "make a stacktrace for me"
    And the exception "type" equals "browserjs"

    # this ensures the first generated stackframe doesn't come from bugsnag's source
    And the error payload field "events.0.exceptions.0.stacktrace.0.method" equals "a"
    And event 0 is handled

  Scenario: calling notify() with a string, getting a generated stacktrace
    When I navigate to the test URL "/handled/script/notify_string.html"
    Then I wait to receive an error
    And the error is a valid browser payload for the error reporting API
    And the exception "errorClass" equals "Error"
    And the exception "message" equals "make a stacktrace for me"
    And the exception "type" equals "browserjs"

    # this ensures the first generated stackframe doesn't come from bugsnag's source
    And the error payload field "events.0.exceptions.0.stacktrace.0.method" equals "a"
    And event 0 is handled

  Scenario: calling window.client.notify() with an object, getting a generated stacktrace
    When I navigate to the test URL "/handled/script/client_notify_object.html"
    Then I wait to receive an error
    And the error is a valid browser payload for the error reporting API
    And the exception "errorClass" equals "Error"
    And the exception "message" equals "make a stacktrace for me"
    And the exception "type" equals "browserjs"

    # this ensure the stacktrace features all of the nested stackframes
    And the error payload field "events.0.exceptions.0.stacktrace.0.method" equals "a"
    And the error payload field "events.0.exceptions.0.stacktrace.1.method" equals "b"
    And the error payload field "events.0.exceptions.0.stacktrace.2.method" equals "c"
    And event 0 is handled

  Scenario: calling window.client.notify() with a string, getting a generated stacktrace
    When I navigate to the test URL "/handled/script/client_notify_string.html"
    Then I wait to receive an error
    And the error is a valid browser payload for the error reporting API
    And the exception "errorClass" equals "Error"
    And the exception "message" equals "make a stacktrace for me"
    And the exception "type" equals "browserjs"

    # this ensure the stacktrace features all of the nested stackframes
    And the error payload field "events.0.exceptions.0.stacktrace.0.method" equals "a"
    And the error payload field "events.0.exceptions.0.stacktrace.1.method" equals "b"
    And the error payload field "events.0.exceptions.0.stacktrace.2.method" equals "c"
    And event 0 is handled

  Scenario: overridden handled state in a callback
    When I navigate to the test URL "/handled/script/callback_override.html"
    Then I wait to receive an error
    And the error is a valid browser payload for the error reporting API
    And the exception "message" ends with "hello"
    # The severity is "error" because only the handled-ness has been changed
    And event 0 is handled with the severity "error"
